package com.stone.framework.core.util;

import java.util.Random;

import org.apache.shiro.crypto.hash.SimpleHash;

public final class Passwords {

    public static final String HASH_ALGORITHM_NAME = "MD5";

    public static final int HASH_ITERATIONS = 1;

    private static final Random RANDOM = new Random();

    public static String encryption(String source, String salt) {
        return new SimpleHash(HASH_ALGORITHM_NAME, source, salt, HASH_ITERATIONS).toHex();
    }

    public static String encryption(String source) {
        return new SimpleHash(HASH_ALGORITHM_NAME, source).toHex();
    }

    public static String buildSalt(int bound) {
        return String.valueOf(RANDOM.nextInt(bound));
    }

}
